{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda_3.7\\lib\\importlib\\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject\n",
      "  return f(*args, **kwds)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from matplotlib import pyplot as plt\n",
    "from sklearn import linear_model\n",
    "from sklearn.model_selection import train_test_split\n",
    "import statsmodels.api as sm #最小二乘\n",
    "from statsmodels.formula.api import ols #加载ols模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>tvcm</th>\n",
       "      <th>magazine</th>\n",
       "      <th>install</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2013-01</td>\n",
       "      <td>6358</td>\n",
       "      <td>5955</td>\n",
       "      <td>53948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2013-02</td>\n",
       "      <td>8176</td>\n",
       "      <td>6069</td>\n",
       "      <td>57300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2013-03</td>\n",
       "      <td>6853</td>\n",
       "      <td>5862</td>\n",
       "      <td>52057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2013-04</td>\n",
       "      <td>5271</td>\n",
       "      <td>5247</td>\n",
       "      <td>44044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2013-05</td>\n",
       "      <td>6473</td>\n",
       "      <td>6365</td>\n",
       "      <td>54063</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     month  tvcm  magazine  install\n",
       "0  2013-01  6358      5955    53948\n",
       "1  2013-02  8176      6069    57300\n",
       "2  2013-03  6853      5862    52057\n",
       "3  2013-04  5271      5247    44044\n",
       "4  2013-05  6473      6365    54063"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读入 ad_result（关于某游戏在电视盒杂志上投入的广告费和所获得的新用户数的信息）数据\n",
    "ad_result_table = pd.read_csv('./data/ad_result.csv')\n",
    "ad_result_table.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0xf9bec67dc8>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAECCAYAAAALqiumAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXvElEQVR4nO3df3Dc9X3n8edr7UVWkTPRyBrnsNKABzq5FGSn7DnmbINwnCtJwKE4aXN3CTd3k/GlxyRzl5nDpEeaIdc5ak2aTqcDvTg4JCWFuQRNgklpoXOuD5fhh1fEqNckbRNigzzhUGU5WETWidv3/fH9qpaxvvKu9F2tVvt6z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u92OCTMzCyL1yTMzCyTQ8LMzDI5JMzMLJNDwiwHkjZK2tjodpjlzSFhlo+N6cNsWfGnm8wWSNLdwK+lL0+Q3EribyLiO5I+S3JR5KPA10juQXUK+HWSGxe+Cvxf4G3A/RHx3xe39WZz80jCbIEi4rMkV0X/bkS8F/gWyQVdANcCjwG7gRciYiswAFwJ/ALwEaCX5NYb71nkpptdkK+4NstZRPydpB5JbwFORcTrkt5JEg6QjCgA/k9EjEs6TnIXUDWguWZzckiY5WMC6AKQJOA54D8CB9LjPwT+GfA/gd8imWYyW/I83WSWj78AbpH0FMmNCb9FEhLfTY9/BfgVSYeAXwEeaEQjzWrlhWszM8vkkYSZmWVySJiZWSaHhJmZZXJImJlZJoeEmZllckiYmVmm/w9n0yGMtwv70QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查看电视广告费和新用户数的散点图\n",
    "plt.rcParams['font.sans-serif']=['SimHei']\n",
    "plt.rcParams['axes.unicode_minus']=False\n",
    "\n",
    "ad_result_table.plot(kind='scatter', x='tvcm', y='install')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0xf9bec88ac8>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAECCAYAAADpdjDfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAaWElEQVR4nO3df3Bd9X3m8fcjW5EVRBqt0ZhidwEXdrMpyM5wxzExBOOYFgIYipPtL8J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O8nquHERcW9kV+Z9FPgvb7Lcroi4FPhHsktIfBL4ekS8B7he0vKiVtDsZHjGYTa3/xMRo5IOA/8P+DlZIIySnaEL2ezgM2Qh8dm89gbwp9PGIekq4Fcj4s3ud/DV/N8XgLcA/xa4WNLvk12M7ixgeD4rZjYfDg6z+v0c+O9kl2YYyGvXAX8QEc9MGfdx4HNTx0k6m+wKq79Rx3Jen/b8OeChiPiOpBvJrl5qVhoHh1n9PgCsBYaAX0haSXZxuD5Jz5NdlvqTwDfJAmbquD8huwfFNyQBfCQinqtzuf8N2C3pz4Hngf9Z3CqZpfO7qszmQdJngQ1ku7LeALZHxD+U2pRZgzk4zMwsid9VZWZmSRwcZmaWxMFhZmZJHBxmZpbEwWFmZkn+P/VGaLwiU1JmAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查看杂志广告费和新用户数的散点图\n",
    "ad_result_table.plot(kind='scatter', x='magazine', y='install')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Coefficients:[[0.96776884 8.82567022]],intercept -6389.96\n",
      "Residual sum of square:1440974.25\n",
      "Score:0.50\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\anaconda_3.7\\lib\\site-packages\\ipykernel_launcher.py:2: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.\n",
      "  \n",
      "D:\\anaconda_3.7\\lib\\site-packages\\ipykernel_launcher.py:3: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    }
   ],
   "source": [
    "# 进行多元回归分析（sklearn）\n",
    "X = ad_result_table[['tvcm','magazine']].as_matrix()\n",
    "y = ad_result_table[['install']].as_matrix()\n",
    "\n",
    "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)\n",
    "\n",
    "reg = linear_model.LinearRegression()\n",
    "reg.fit(X_train,y_train)\n",
    "print('Coefficients:%s,intercept %.2f' % (reg.coef_, reg.intercept_))#权重向量即为每个特征的相关系数\n",
    "print(\"Residual sum of square:%.2f\" % np.mean((reg.predict(X_test) - y_test) ** 2))#均方误差，每个特征的（预测值-真实值的平方）的平均值\n",
    "print('Score:%.2f' % reg.score(X_test, y_test))#得分\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>OLS Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>         <td>install</td>     <th>  R-squared:         </th> <td>   0.938</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                   <td>OLS</td>       <th>  Adj. R-squared:    </th> <td>   0.920</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   52.86</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>             <td>Sun, 19 Jul 2020</td> <th>  Prob (F-statistic):</th> <td>5.97e-05</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                 <td>15:09:51</td>     <th>  Log-Likelihood:    </th> <td> -84.758</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Observations:</th>      <td>    10</td>      <th>  AIC:               </th> <td>   175.5</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Residuals:</th>          <td>     7</td>      <th>  BIC:               </th> <td>   176.4</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Df Model:</th>              <td>     2</td>      <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th> <td>  188.1743</td> <td> 7719.131</td> <td>    0.024</td> <td> 0.981</td> <td>-1.81e+04</td> <td> 1.84e+04</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>tvcm</th>      <td>    1.3609</td> <td>    0.517</td> <td>    2.630</td> <td> 0.034</td> <td>    0.137</td> <td>    2.584</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>magazine</th>  <td>    7.2498</td> <td>    1.693</td> <td>    4.283</td> <td> 0.004</td> <td>    3.247</td> <td>   11.252</td>\n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "  <th>Omnibus:</th>       <td> 0.992</td> <th>  Durbin-Watson:     </th> <td>   0.881</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Prob(Omnibus):</th> <td> 0.609</td> <th>  Jarque-Bera (JB):  </th> <td>   0.795</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Skew:</th>          <td> 0.534</td> <th>  Prob(JB):          </th> <td>   0.672</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Kurtosis:</th>      <td> 2.124</td> <th>  Cond. No.          </th> <td>1.63e+05</td>\n",
       "</tr>\n",
       "</table><br/><br/>Warnings:<br/>[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.<br/>[2] The condition number is large, 1.63e+05. This might indicate that there are<br/>strong multicollinearity or other numerical problems."
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                            OLS Regression Results                            \n",
       "==============================================================================\n",
       "Dep. Variable:                install   R-squared:                       0.938\n",
       "Model:                            OLS   Adj. R-squared:                  0.920\n",
       "Method:                 Least Squares   F-statistic:                     52.86\n",
       "Date:                Sun, 19 Jul 2020   Prob (F-statistic):           5.97e-05\n",
       "Time:                        15:09:51   Log-Likelihood:                -84.758\n",
       "No. Observations:                  10   AIC:                             175.5\n",
       "Df Residuals:                       7   BIC:                             176.4\n",
       "Df Model:                           2                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "Intercept    188.1743   7719.131      0.024      0.981   -1.81e+04    1.84e+04\n",
       "tvcm           1.3609      0.517      2.630      0.034       0.137       2.584\n",
       "magazine       7.2498      1.693      4.283      0.004       3.247      11.252\n",
       "==============================================================================\n",
       "Omnibus:                        0.992   Durbin-Watson:                   0.881\n",
       "Prob(Omnibus):                  0.609   Jarque-Bera (JB):                0.795\n",
       "Skew:                           0.534   Prob(JB):                        0.672\n",
       "Kurtosis:                       2.124   Cond. No.                     1.63e+05\n",
       "==============================================================================\n",
       "\n",
       "Warnings:\n",
       "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
       "[2] The condition number is large, 1.63e+05. This might indicate that there are\n",
       "strong multicollinearity or other numerical problems.\n",
       "\"\"\""
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 进行多元回归分析（statsmodels）\n",
    "lm=ols('install ~ tvcm + magazine',data=ad_result_table).fit()\n",
    "lm.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "nbTranslate": {
   "displayLangs": [
    "*"
   ],
   "hotkey": "alt-t",
   "langInMainMenu": true,
   "sourceLang": "en",
   "targetLang": "fr",
   "useGoogleTranslate": true
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
